-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use requests.Session object to reuse connections in PolicyClient #33035
Use requests.Session object to reuse connections in PolicyClient #33035
Conversation
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
|
@sven1977 this has been marked as stale, could someone do a review? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
|
@sven1977 this has been marked as stale, could someone do a review? |
@sven1977 @kouroshHakha According to https://requests.readthedocs.io/en/latest/user/advanced/#session-objects, sessions can bring significant speedups. I've timed this a little and from a quick look I could not observe a speedup. |
I wonder if keeping the session open can cause any problems / leaks. Usually it has to be closed. Nevertheless the PR makes sense. @MattiasDC if you were to do session.close() where should that happen? |
Hi @kouroshHakha, I agree that it's cleaner to close the session. Typically a session is automatically closed when you use it as a context manager. There is an example in the requests doc. Alternatively we simply call |
@MattiasDC yep that's what I thought about too. How about we make an optional arg for policyClient called session that allows users to pass in their pre constructed session from outside. In this case, the caller will be responsible for closing the session. However if the user does not provide the session we resort to the old method? |
9de94d6
to
e3586db
Compare
@kouroshHakha I agree with your suggestion and pushed it |
e3586db
to
0df7eee
Compare
Cool stuff! :)
Thanks for this PR! |
…e efficiently in PolicyClient Signed-off-by: mattias <mattias.decharleroy@gmail.com>
0df7eee
to
596eab0
Compare
@ArturNiederfahrenhorst can you have a look at the ones still failing and let me know if they are caused by my PR? |
All RLlib tests are passing. Merging now ... |
…urce more efficiently in PolicyClient (ray-project#33035) Signed-off-by: mattias <mattias.decharleroy@gmail.com>
…urce more efficiently in PolicyClient (ray-project#33035) Signed-off-by: mattias <mattias.decharleroy@gmail.com> Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
Why are these changes needed?
Uses connections/resources more efficiently in PolicyClient. By using a
requests.Session
object, instead of usingrequests
directly, connections are reused.Related issue number
Closes #30136
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.